import os

def walk_dir(rootdir):
    newdirs = []
    filelist = []
    newdirs.append(rootdir)
    # BFS
    while len(newdirs):
        for dir in newdirs:
            newdirs.remove(dir)
            files = os.listdir(dir)
            for file in files:
                if os.path.isdir('file'):
                    newdirs.append(os.path.join(dir, file))
                    continue
                filelist.append(os.path.join(dir, file))
    return filelist

def read_file(path):
    buf = None
    if not os.path.isdir(path):
        f = open(path, 'r')
        buf = f.read()
        f.close()
    else:
        raise IOError, 'isdir'
    return buf

def write_file(path, content):
    if not os.path.isdir(path):
        f = open(path, 'w')
        f.write(content)
        f.close()
    else:
        raise IOError, 'isdir'

    
